using System;
using System.Security.Policy;
using System.Collections;

namespace my.Fetcher
{
	/// <summary>
	/// understands the storage of urls
	/// </summary>
	public interface IUrlStack
	{
		void Add(Url Key);
		Url GetNext();
		bool IsPresent(Url Key);
		int Count{get;}
		bool HasNext();
	}

	/// <summary>
	/// understands the storage or url stack 
	/// </summary>
	public class UrlStack : IUrlStack
	{
		protected Hashtable hashList;
		protected Queue queueList;

		public UrlStack()
		{
			this.hashList = new Hashtable();
			this.queueList = new Queue();
		}
		public virtual void Add(Url Key)
		{
			String UrlStr = new String(Key.Value.ToCharArray());
			this.hashList.Add(Key, UrlStr);
			this.queueList.Enqueue(Key);
		}

		public virtual bool HasNext() {
			return queueList.Count > 0;
		}

		public virtual Url GetNext()
		{
			Url returnVal=new Url("http://xilun");
			if(queueList.Count > 0)
			{
				returnVal = (Url)this.queueList.Peek();
			}
			this.Remove();
			return returnVal;
		}

		public virtual bool IsPresent(Url Key)
		{
			return hashList.Contains(Key);
		}

		public virtual int Count
		{
			get
			{
				return queueList.Count;
			}
		}

		protected virtual void Remove()
		{
			Url Key = (Url)this.queueList.Dequeue();
			this.hashList.Remove(Key);
		}
	}
}
